# coding:utf-8
import json

'''
解析json
'''


def operator():
    # jsonstr = {"status": 0, "result": [{"x": 117.3606268606138, "y": 38.446671264033977}]}
    # dumps 针对对象，所以上面的不能加‘’
    # 以下是格式化输出
    # dumps 出来的类型是 <type 'str'> 不能做字典取值
    # jsonObject = json.dumps(obj=jsonstr, sort_keys=True, indent=4, separators=(',', ':'))

    jsonstr = '{"status": 0, "result": [{"x": 117.3606268606138, "y": 38.446671264033977}]}'

    print type(jsonstr)
    jsonObject = json.loads(jsonstr)
    #
    print type(jsonObject)
    print jsonObject['status']
    print type(jsonObject['status'])
    # print jsonObject['result'][0]['x']

    # jsonArray
    resultStr = jsonObject['result']
    for i in resultStr:
        print i['x']


if __name__ == '__main__':
    operator()
